package com.rhomobile.rhodes.extmanager;

import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
import android.graphics.Rect;


public interface IRhoExtManager {

    void registerExtension(String strName, IRhoExtension ext);
    IRhoExtension getExtByName(String strName);

    void addRhoListener(IRhoListener listener);

    /**
     * Handler to notify RhoExtManager about new configuration
     * @param config - IRhoConfig implementation
     * @param name - configuration name used to identify the config like 'rhoelements' od 'rhoconfig'
     */
    void setConfig(String name, IRhoConfig config);
    IRhoConfig getConfig(String name);

    Context getContext();

    IRhoWebView getWebView();

    /**
     * RhodesActivity top level View getter
     * @return RhodesActivity top level View
     */
    View getTopView();

    /**
     * 
     * @param name - build configuration item name
     * @return build configuration item value
     */
    String getBuildConfigItem(String name);

    void onUnhandledProperty(String moduleName,String name,String value, IRhoWebView ext);
    void executeRubyCallback(String callback,String callbackBody,String callbackData, boolean waitForResponse);
    void executeRubyCallbackWithJsonBody(String szCallback, String callbackBody, String callbackData, boolean waitForResponse);
    void requireRubyFile(String szFilePath);
    
    void navigate(String url);
    //boolean existsJavascript(String jsFunction);
    void executeJavascript(String jsFunction);

    String getCurrentUrl();
    void stopNavigate(IRhoExtension.LoadErrorReason reason);
    void historyForward();
    void historyBack();
    void refreshPage(boolean bFromCache);
    void quitApp();
    void setFullScreen(boolean fullScreen);
    void minimizeApp();
    void restoreApp();
    void zoomPage(float fZoom);
    void zoomText(int nZoom);

    /**
     * Handler to notify RhoExtManager that new configuration is going to apply
     * @return true if it is allowed for extension to navigate start page itself
     */
    boolean onStartNewConfig();
    
    /**
	 * Called when a key press is detected by the RhodesActivity. Be aware, this interface will
	 * provide more than just key down events. See the Android documentation for the KeyEvent
	 * class for more information
	 * @param keyCode the code of the key pressed/released etc.
	 * @param event the KeyEvent generated by the key press/release etc.
	 * @return True if the listener has consumed the event, false to let it bubble to other views. 
	 */
	boolean onKey(int keyCode, KeyEvent event);
	
    /**
     * Stops the input IRhoListener from receiving keyEvents.
     * @param listener the listener to de-register
     */
	void stopKeyEventUpdates(IRhoListener listener);
	
    /**
     * Registers the IRhoListener to receive keyEvents. KeyEvents will be dispatched in order of registering.
     * @param listener the listener object to send keyEvents to
     */
	void startKeyEventUpdates(IRhoListener listener);
	
    /**
     * Registers the IRhoListener to receive keyEvents
     * @param listener the listener object to send keyEvents to
     * @param makeImportant makes the input listener head of the queue so it receives keyEvents first.
     */
    void startKeyEventUpdates(IRhoListener listener, boolean makeImportant);
    
    /**
     * Accounts and returns next request code which may be used by Activity.startActivityForResult() call
     * @return new request code
     */
    int getActivityResultNextRequestCode(IRhoListener listener);
    
    /**
     * Erases passed request code from activity result listeners map
     * @param requestCode value to erase from map
     */
    void dropActivityResultRequestCode(int requestCode);

    void onInputMethod(View view, boolean enabled, String type, Rect area);
}


